import 'package:blog/api/api_handle.dart';
import 'package:blog/src/generated/models/setting.pb.dart';
import 'package:get_it/get_it.dart';
import 'package:flutter/foundation.dart';
import 'package:dio/dio.dart';

import 'api/api.dart';

GetIt locator = GetIt.instance;

setupLocator() async {
  Config cfg = kDebugMode ? ConfigDebug() : ConfigProduct();
  Dio _dio = Dio(BaseOptions(
      baseUrl: cfg.baseUrl,
      connectTimeout: cfg.connectTimeout,
      receiveTimeout: cfg.receiveTimeout));
  var _handle = ProtoApiHandle();

  locator.registerSingleton<Config>(cfg);
  locator.registerSingleton<ApiHandle>(_handle);
  locator.registerSingleton<Api>(DioApiImpl(_dio, _handle));

  var siteSetting = await locator<Api>().getSiteSetting();
  locator.registerSingleton<SiteSetting>(siteSetting as SiteSetting);

}
